package fragment;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.TranslateAnimation;
import android.widget.Button;

import com.example.administrator.customview.R;

/**
 * Created by eyesee on 2017/4/22.
 */

public class MenuFragment extends DialogFragment {

    private Dialog mDialog;
    private View mView;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        mDialog = new Dialog(getActivity());

//        mDialog.getWindow().getAttributes().windowAnimations = R.style.dialogAnim;
//        mDialog.getWindow().setWindowAnimations(R.style.dialogAnim);
        mView = View.inflate(getActivity(), R.layout.menufragment_view, null);
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialog.setContentView(mView);
        mDialog.setCanceledOnTouchOutside(true);

        //动画
        TranslateAnimation animation = new TranslateAnimation(-mView.getMeasuredWidth(), 0, 0, 0);
        animation.setDuration(1000);
        mView.setAnimation(animation);
        animation.start();

        init();
        Window window = mDialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.LEFT;
        params.width = 400;
        params.height = 1000;
        window.setAttributes(params);
        return mDialog;
    }

    private void init() {
        Button button = (Button) mView.findViewById(R.id.menu2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MenuFragmentTwo fragmentTwo = new MenuFragmentTwo();
                fragmentTwo.show(getFragmentManager(), "");
                mDialog.dismiss();
            }
        });
    }
}
